Closed
Conversation
Complete migration of PerpsController implementation from MetaMask Mobile to enable cross-platform sharing of Perps (Perpetual Futures) functionality. This includes: - PerpsController (~3,000 lines) with full trading functionality - 8 state selectors for UI integration - Comprehensive TypeScript type definitions - 18 utility modules for calculations, formatting, validation - 8 service modules (Trading, MarketData, Eligibility, etc.) - HyperLiquidProvider with full protocol integration - AggregatedPerpsProvider for multi-provider support - Platform services for HyperLiquid client, subscriptions, wallet - Test infrastructure with mocks and 40 unit tests The package uses dependency injection via PerpsPlatformDependencies interface to remain platform-agnostic, allowing Mobile and Extension to provide their own implementations while sharing core business logic.
Add 17 test files migrated from metamask-mobile covering: - Amount conversion, margin, PnL, and position calculations - Order book grouping and order utilities - Market data transformation and sorting - HyperLiquid adapter and validation - TP/SL validation and string parsing utilities Add MIGRATION.md documenting migration status and coverage priorities. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update @metamask/transaction-controller to ^62.12.0 - Add PR references to CHANGELOG.md - Regenerate yarn.lock Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
4 tasks
4 tasks
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 3, 2026
…7941) ## Explanation Syncs `PerpsController` from Mobile into Core as `@metamask/perps-controller` for npm publishing. **Architecture (latest):** Cross-controller communication uses the standard `@metamask/messenger` pattern — `messenger.call()` and `messenger.subscribe()`. Typed `PerpsControllerAllowedActions` / `PerpsControllerAllowedEvents` define the contract. The only DI remaining is `PerpsPlatformDependencies.rewards` (RewardsController is not yet in Core) and platform-specific adapters (logger, metrics, tracer, stream manager, etc.). This addresses Mark Stacey's concern from the ADR-42 review: PerpsController uses the same messenger architecture as all other Core controllers, with no special DI bridging for controller-to-controller calls. **Messenger actions used:** | Action | Controller | |--------|-----------| | `AccountTreeController:getAccountsFromSelectedAccountGroup` | AccountTreeController | | `KeyringController:getState` | KeyringController | | `KeyringController:signTypedMessage` | KeyringController | | `NetworkController:getState` | NetworkController | | `NetworkController:getNetworkClientById` | NetworkController | | `NetworkController:findNetworkClientIdByChainId` | NetworkController | | `TransactionController:addTransaction` | TransactionController | | `AuthenticationController:getBearerToken` | AuthenticationController | | `RemoteFeatureFlagController:getState` | RemoteFeatureFlagController | **Messenger events subscribed:** - `RemoteFeatureFlagController:stateChange` - `AccountTreeController:selectedAccountGroupChange` **Approach:** Mobile remains the source of truth. A sync script (`validate-core-sync.sh`) copies controller source to this package, verifies build + lint, and writes a `.sync-state.json` with commit hashes and source checksum for conflict detection. This is a transitional mechanism that goes away when Mobile folds into Core as `apps/mobile`. **Key components:** - `PerpsController` — main controller with state management, messenger integration, and multi-provider orchestration - `HyperLiquidProvider` / `MYXProvider` — DEX-specific provider implementations - `AggregatedPerpsProvider` — multi-provider aggregation layer - `ProviderRouter` — routes operations to the appropriate provider - `SubscriptionMultiplexer` — real-time WebSocket data aggregation - 13 services: Trading, MarketData, Account, Deposit, Eligibility, FeatureFlagConfiguration, HyperLiquidClient, HyperLiquidSubscription, HyperLiquidWallet, MYXClient, DataLake, RewardsIntegration, TradingReadinessCache - `PerpsPlatformDependencies` — platform-agnostic injection interface (rewards, logger, metrics, tracer, stream manager, feature flags, market data formatters, cache invalidator) **CI / Testing:** A minimal placeholder test (`tests/placeholder.test.ts`) is included to satisfy Core's CI requirement. Full unit tests remain in Mobile (27 suites, 1295 tests passing) and will be migrated when development moves fully to Core. ## References - Builds on #7654 (initial `perps-controller` package scaffolding) - Supersedes #7749 (closed — first full migration attempt) - Related: #7841 (draft — preview publishing test) - Mobile messenger migration: [metamask-mobile@feat/perps/di-refactor-remove-controller-deps](https://github.com/MetaMask/metamask-mobile/tree/feat/perps/di-refactor-remove-controller-deps) - Mobile preparation: [metamask-mobile#26064](MetaMask/metamask-mobile#26064) (ESLint alignment + `validate-core-sync.sh`) - Mobile isolation: [metamask-mobile#25813](MetaMask/metamask-mobile#25813) (isolated perps code, converted imports) - Architecture position: [PerpsController Location — Position v2 (Post-DI)](https://consensyssoftware.atlassian.net/wiki/spaces/PRDC/pages/400956981249/PerpsController+package+Location+Position+v2+Post-DI) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - Placeholder test included for CI. Full unit tests remain in Mobile and will be migrated when development moves fully to Core. - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them - No breaking changes — messenger migration is internal; existing public API is preserved <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > Large change that introduces/rewires perps trading flows, WebSocket subscriptions, feature-flagged provider switching, and transaction submission via `TransactionController`, increasing risk of runtime, data consistency, and funds-impacting regressions. Testing/coverage is intentionally reduced to a placeholder in Core, so validation relies on Mobile’s test suite. > > **Overview** > Replaces the stub `PerpsController` with the full synced implementation, expanding controller state/metadata and exposing a broad messenger API for perps operations (orders, positions, funding, eligibility, deposits/withdrawals, provider/network switching, and live-data subscriptions). > > Adds multi-provider support (HyperLiquid default, MYX behind a feature flag, and an `AggregatedPerpsProvider` mode), plus background market/user-data preloading and stream-pausing helpers to reduce UI races during trading operations. > > Updates packaging for publishing: adds a sync provenance file, expands runtime/dev dependencies for provider + cross-controller integrations, adjusts Jest coverage to only include `tests/placeholder.test.ts`, and removes the prior controller unit test while updating the changelog to document the full initial release contents. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2fbf70d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Nick Gambino <35090461+gambinish@users.noreply.github.com> Co-authored-by: Nicholas Gambino <nicholas.gambino@consensys.net> Co-authored-by: Nick Gambino <ngambino0192@gmail.com> Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Creating a separate branch from #7749 to test preview package publishing via metamask bot. This is just an internal draft, don't worry about reviewing.
References
Checklist